<template>
  <a-modal title='单位选择(可通过双击行选择)' :dialog-style="{ top: '10px' }" :width='900' :visible='visible' :confirmLoading='loading' :footer='null' @ok='handleSubmit' @cancel='handleCancel'>
    <f-search-form :more='false' @searchHandler='searchHandler'>
      <f-search-form-item label='单位名称' name='title' style='width:400px' />
    </f-search-form>
    <f-table ref='table' rowKey='customCode' :rowSelection='rowSelection' v-if='visible' :scroll='{y:300}' @dblclick='dblclick' :columns='columns' :multiple='false' :showRadio='true' :operator='operator' :params='queryParam' :api='api.custom.selectTop20HyCustomList' @onSelectChange='onSelectChange'>
    </f-table>
    <custom-drawer ref='drawer'></custom-drawer>
  </a-modal>
</template>
<script>
import api from "../js/api"
import CustomDrawer from "@/views/module/business/custom/custom_drawer"

export default {
  name: "SelectHyRemoterCustomModal",
  props: {
    checkDate: {
      type: Boolean,
      default: true
    }
  },
  data() {
    let operator = []
    return {
      refs: this.$refs,
      api: Object.assign(api, this.api),
      loading: false,
      visible: false,
      selectedRowKeys: [],
      selectedRows: [],
      //列表初始化查询参数
      queryParam: {},

      // 表头
      columns: [
        {
          title: "单位名称",
          align: "left",
          ellipsis: true,
          width: "240px",
          dataIndex: "customName",
          customCell: this.renderTdBackground
        },
        {
          title: "联系人",
          align: "left",
          width: "100px",
          dataIndex: "linkMan"
        },
        {
          title: "仓库地址",
          align: "left",
          width: "180px",
          ellipsis: true,
          dataIndex: "ckAddress"
        },
        {
          title: "业务片区",
          align: "left",
          width: "80px",
          ellipsis: true,
          dataIndex: "sendArea"
        },
        {
          title: "是否首营",
          align: "center",
          width: "60px",
          dataIndex: "isFirst"
        }
      ],
      operator: operator
    }
  },
  computed: {
    rowSelection() {
      return {
        type: "radio",
        getCheckboxProps: record => ({
          props: {
            disabled: record.allowSelect == false && this.checkDate == true,
            name: record.allowSelect
          }
        })
      }
    }
  },
  methods: {
    renderTdBackground(record, flag) {
      if (record.allowSelect == false && this.checkDate == true) {
        return {
          style: {
            "background-color": "rgb(255,150,150)",
            "text-decoration": "line-through"
          }
        }
      }
    },
    open() {
      this.visible = true
      this.selectedRowKeys = []
      this.selectedRows = []
    },
    close() {
      this.$emit("close")
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    dblclick(record, event) {
      if (record.allowSelect == false && this.checkDate == true) {
        let zlDateTag = record.zlDateTag
        let message = ""
        if (zlDateTag == false) {
          message += "质量证书资质到期   "
        }
        let ypDateTag = record.ypDateTag
        if (ypDateTag == false) {
          message += "药品许可资质到期    "
        }
        let sqDateTag = record.sqDateTag
        if (sqDateTag == false) {
          message += "授权到期   "
        }
        let sfzDateTag = record.sfzDateTag
        if (sfzDateTag == false) {
          message += "身份证到期   "
        }
        let zbDateTag = record.zbDateTag
        if (zbDateTag == false) {
          message += "质保协议到期   "
        }
        let qxDateTag = record.qxDateTag
        if (qxDateTag == false) {
          message += "器械许可协议到期   "
        }
        let ngDateTag = record.ngDateTag
        if (ngDateTag == false) {
          message += "年度公示到期   "
        }
        let zzDateTag = record.zzDateTag 
        if (zzDateTag == false) {
          message += "执照到期   "
        }
        let wtsDateTag = record.wtsDateTag
        if (wtsDateTag == false) {
          message += "委托书到期   "
        }
        this.$message.error(message)
        return
      }
      let selectedRowKeys = []
      let selectedRows = []
      selectedRowKeys.push(record.customCode)
      selectedRows.push(record)
      this.$emit("onSelectChange", selectedRowKeys, selectedRows)
      this.close()
    },
    handleSubmit() {
      this.$emit("onSelectChange", this.selectedRowKeys, this.selectedRows)
      this.close()
    },
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
    }
  },
  created() {
  },
  components: { CustomDrawer }
}
</script>

<style scoped lang='less' rel='stylesheet/less'>

</style>
